<!-- eslint-disable max-lines -->
<template>
  <!-- 新增见证事项 -->
  <el-dialog
    draggable
    :title="dialogTitle"
    width="809px"
    class="witness-matters-dialog"
    :close-on-click-modal="false"
    :visible.sync="visible"
    :show-close="false"
    @close="closeFn"
  >
    <!-- {{ type }} -->
    <el-form
      ref="formDataAdd"
      :model="formData"
      :rules="rulesData"
      label-width="107px"
      :inline="false"
      size="normal"
      on-submit="return false;"
    >
      <!-- {{ taskObj.industryTypeAndTenderMode }} -->
      <template>
        <el-row>
          <el-col :span="11" :offset="0">
            <el-form-item label="行业类型">
              <el-select
                :disabled="type === 'edit'"
                v-model="industry"
                style="width: 248px"
                placeholder="请选择"
                @change="industryChangeFn"
              >
                <el-option
                  v-for="item in taskObj.industryTypeAndIndustry"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" :offset="0">
            <el-form-item label="交易方式">
              <el-select
                :disabled="type === 'edit'"
                v-model="tenderMode"
                placeholder="请选择"
                style="width: 251px"
                @change="tenderModeFn"
              >
                <el-option v-for="item in liveStatusArr" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <!-- v-if="xugai != 'edit'" -->
            <el-form-item label="见证事项" prop="valueCode" class="fromriodr">
              <el-radio-group :disabled="type === 'edit'" v-model="formData.valueCode" @change="radioBox($event)">
                <el-radio label="YES">系统预置事项</el-radio>
                <el-radio label="NO">自定义事项</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="13">
            <!--
                @change="itemOrderFn"  label-width="92px" -->
            <!-- {{ formData.statusArr }} -->
            <!-- {{ orderTotal }} -->
            <el-form-item label="规则排序" prop="itemOrder" class="fromriodr">
              <template
                v-if="
                  (formData.statusArr && formData.statusArr.length > 1 && formData.scenes[0] !== 'EXISTING') ||
                  (itemOrder <= 0 && type === 'add')
                "
              >
                <el-select
                  filterable
                  value=""
                  :disabled="true"
                  placeholder="默认各环节最后"
                  style="width: 251px"
                ></el-select>
              </template>
              <template v-else>
                <!-- && type === 'add' -->
                <el-select
                  :disabled="formDataLoading"
                  filterable
                  v-model="itemOrder"
                  placeholder="请选择"
                  style="width: 251px"
                  @change="itemOrderChangeFn"
                >
                  <template v-if="orderTotal > 0">
                    <el-option v-for="item in orderTotal" :key="item" :label="item" :value="item" />
                  </template>
                </el-select>
              </template>
              <el-link class="ui-ml5" type="primary" v-if="formDataLoading" disabled>
                <i class="el-icon-loading"></i>
              </el-link>
            </el-form-item>
          </el-col>
        </el-row>
      </template>
      <!-- {{ formData.scenes }} -->
      <el-row>
        <el-col :span="11" :offset="0">
          <el-form-item
            label="见证场景"
            :rules="{
              required: true,
              message: '不能为空',
              trigger: 'blur'
            }"
          >
            <el-cascader
              :disabled="type === 'edit'"
              style="width: 248px"
              :show-all-levels="false"
              option-max-width="300px"
              v-model="formData.scenes"
              :options="scenesOptions"
              @change="scenesChangeFn"
            ></el-cascader>
          </el-form-item>
        </el-col>
        <el-col :span="13" :offset="0">
          <!-- {{ formData.scenes }}
          {{ formData.statusArr }}
          {{ formData.status }}
          {{ statusOptions }} -->
          <!--  编辑的时候 数据不对   PEOPLE -->
          <!-- TODO 既定见证流程-单选； 人工、暂停、恢复-多选-->
          <template v-if="Array.isArray(formData.scenes) && formData.scenes[0] !== 'EXISTING'">
            <el-form-item
              label="见证环节"
              prop="statusArr"
              :rules="{
                required: true,
                message: '不能为空',
                trigger: 'change'
              }"
            >
              <!-- {{ formData.statusArr }} -->
              <el-select
                :disabled="type === 'edit'"
                key="formData.statusArr"
                multiple
                collapse-texts
                v-model="formData.statusArr"
                style="width: 251px"
                placeholder="请选择"
                @change="statusArrChangeFn"
                @visible-change="statusArrBlurFn"
              >
                <el-option
                  v-for="(item, index) in statusOptions"
                  :key="item.abridge + index"
                  :label="item.label"
                  :value="item.abridge"
                />
              </el-select>
            </el-form-item>
          </template>
          <template v-else>
            <el-form-item
              label="见证环节"
              prop="status"
              :rules="{
                required: true,
                message: '不能为空',
                trigger: 'change'
              }"
            >
              <el-select
                :disabled="type === 'edit'"
                key="formData.status"
                v-model="formData.status"
                style="width: 251px"
                placeholder="请选择"
                @change="statusChangeFn"
              >
                <el-option
                  v-for="item in statusOptions"
                  :key="item.abridge"
                  :label="item.label"
                  :value="item.abridge"
                />
              </el-select>
            </el-form-item>
          </template>
        </el-col>
      </el-row>
      <el-form-item
        label="见证事项名称"
        v-if="formData.valueCode == 'NO'"
        prop="jianzheng"
        :rules="{
          required: true,
          message: formData.valueCode == 'NO' ? '事项名称不能为空' : '请选择见证事项名称',
          trigger: ['blue', 'change']
        }"
      >
        <el-input v-model="formData.jianzheng" maxlength="100" placeholder="请输入内容" style="width: 600px" />
      </el-form-item>
      <el-form-item
        label="见证事项名称"
        v-if="formData.valueCode == 'YES'"
        prop="jianzheng"
        :rules="{
          required: true,
          message: formData.valueCode == 'NO' ? '事项名称不能为空' : '请选择见证事项名称',
          trigger: 'change'
        }"
      >
        <el-select
          :disabled="formDataLoading || !tenderMode || !industry || !formData.status || type === 'edit'"
          v-model="formData.jianzheng"
          style="width: 600px"
          placeholder="请选择"
          @change="shixiangDataChange($event)"
        >
          <el-option
            v-for="item in shixiangData"
            :key="item.itemCode"
            :label="item.itemName"
            :value="item.itemCode"
            :disabled="item.disabled"
          />
        </el-select>
        <el-link class="ui-ml5" type="primary" v-if="formDataLoading" disabled>
          <i class="el-icon-loading"></i>
        </el-link>
      </el-form-item>
      <template v-for="(domain, index) in formData.domains">
        <el-form-item
          :key="index + 'a'"
          :label="index == 0 ? '正常' : ' '"
          :class="{ 'hide-form-label-sign': index !== 0 }"
          :prop="'domains.' + index + '.sceneRecord'"
          :rules="{
            required: true,
            message: '不能为空',
            trigger: 'change'
          }"
        >
          <el-input
            v-model="domain.sceneRecord"
            maxlength="100"
            placeholder="请输入"
            style="width: 598px"
            :disabled="domain.isSystem == 'YES' ? true : false"
          >
            <template slot="append">
              <el-radio-group v-model="domain.defaultItem" @change="ridioChange(index)">
                <el-radio label="DEFAULT">设为默认</el-radio>
              </el-radio-group>
            </template>
          </el-input>
          <el-button
            v-if="index == 0"
            icon="el-icon-circle-plus-outline"
            type="text"
            style="font-size: 16px; margin-left: 4px"
            @click.prevent="addDomain()"
          />
          <el-button
            :disabled="formData.domains.length == 1"
            icon="el-icon-remove-outline"
            type="text"
            style="font-size: 16px; margin-left: 4px"
            @click.prevent="removeDomain(domain)"
          />
        </el-form-item>
        <el-form-item lable="" :key="index + 'a2'">
          <el-input
            v-model="domain.record"
            placeholder="请输入见证记录"
            type="textarea"
            style="width: 598px"
            maxlength="200"
            show-word-limit
          />
        </el-form-item>
      </template>
      <template v-for="(domain, index) in formData.domainss">
        <el-form-item
          :key="index + 'b'"
          :label="index == 0 ? '异常' : ' '"
          :class="{ 'hide-form-label-sign': index !== 0 }"
          :prop="'domainss.' + index + '.sceneRecord'"
          :rules="{
            required: true,
            message: '不能为空',
            trigger: 'change'
          }"
        >
          <el-input
            v-model="domain.sceneRecord"
            :disabled="domain.isSystem == 'YES' ? true : false"
            maxlength="100"
            placeholder="请输入"
            style="width: 598px"
          >
            <template slot="append">
              <el-radio-group v-model="domain.defaultItem" @change="ridioChanges(index)">
                <el-radio label="DEFAULT">设为默认</el-radio>
              </el-radio-group>
            </template>
          </el-input>
          <el-button
            v-if="index == 0"
            icon="el-icon-circle-plus-outline"
            type="text"
            style="font-size: 16px; margin-left: 4px"
            @click.prevent="addDomains()"
          />
          <el-button
            :disabled="formData.domainss.length == 1"
            icon="el-icon-remove-outline"
            type="text"
            style="font-size: 16px; margin-left: 4px"
            @click.prevent="removeDomains(domain)"
          />
        </el-form-item>
        <el-form-item lable="" :key="index + 'b2'">
          <el-input
            v-model="domain.record"
            placeholder="请输入见证记录"
            type="textarea"
            style="width: 598px"
            maxlength="200"
            show-word-limit
          />
        </el-form-item>
      </template>
      <!-- <el-form-item style="text-align: right; margin-top: 10px">
        <el-button type="primary" :loading="loadingBtn" @click="submitFn('formDataAdd')">确定</el-button>
        <el-button @click="cancelFn('formDataAdd')">取消</el-button>
      </el-form-item> -->
    </el-form>
    <span slot="footer">
      <el-button type="primary" :loading="loadingBtn" @click="submitFn('formDataAdd')">确定</el-button>
      <el-button @click="cancelFn('formDataAdd')">取消</el-button>
    </span>
  </el-dialog>
</template>
<script>
  // import { newAddPeople, itemDictUpdate } from "../../api/api.js";
  export default {
    name: "WitnessMatterDialog",
    components: {},
    props: {
      industryTypeAndIndustryArr: {
        type: Array,
        default() {
          return [];
        }
      },
      // liveStatusArr: {
      //   type: Array,
      //   default() {
      //     return [];
      //   }
      // },
      // statusOptions: {
      //   type: Array,
      //   default() {
      //     return [];
      //   }
      // },
      type: {
        type: String,
        default: "add"
      },
      orderInitTotal: {
        type: Number,
        default: 0
      },
      shixiangInitData: {
        type: Array,
        default() {
          return [];
        }
      },
      formInitData: {
        type: Object,
        default() {
          return {};
        }
      },
      taskObj: {
        type: Object,
        default() {
          return {};
        }
      },
      show: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        linkValOld: null,
        statusArrOld: null,
        loadingBtn: false,
        formDataLoading: false,
        visible: false,
        dialogTitle: "",
        xugai: "",
        deleteIds: [],
        liveStatusArr: [],
        statusOptions: [],
        scenesOptions: [],
        shixiangData: [],
        shixiangDataChildrenYC: [],
        shixiangDataChildrenZC: [],
        industry: "",
        tenderMode: "",
        itemOrder: "", // 排序
        orderTotal: 0, // 排序下拉
        formData: {},
        rulesData: {
          valueCode: [{ required: true, message: "请选择任务分配", trigger: "blur" }],
          jianzheng: [
            {
              required: true,
              message: "请选择见证事项名称",
              trigger: ["blur", "change"]
            }
          ]
        }
      };
    },
    computed: {},
    watch: {
      orderInitTotal(val) {
        console.log("totle", val);
        // 调接口走这里，编辑，走show
        this.orderTotal = val;
        if (this.type === "add") {
          this.orderTotal = val + 1;
          this.itemOrder = this.orderTotal;
        } else {
          this.orderTotal = val;
          //   this.itemOrder = this.formInitData.itemOrder;
        }
      },
      shixiangInitData(val) {
        console.log("shixiangInitData", val);
        console.log("total", this.orderInitTotal);
        this.shixiangData = JSON.parse(JSON.stringify(val));
        this.formDataLoading = false;
      },
      show(val) {
        console.log("val", val);
        console.log("this.currRowData", this.currRowData);
        this.visible = val;
        if (val) {
          this.pageInitFn();
          this.formDataLoading = true;
          this.loadingBtn = false;
          // this.shixiangData = this.shixiangInitData;industryTypeAndTenderMode:Array
          this.xugai = this.type;
          console.log("this.formInitData", this.formInitData);
          if (this.type === "add") {
            this.dialogTitle = "新增见证事项";
            // 排序新增加1
            this.orderTotal = this.orderInitTotal + 1;
            console.log("totle", this.orderTotal);
            this.itemOrder = this.orderTotal;
          } else {
            this.dialogTitle = "编辑见证事项";
            this.orderTotal = this.orderInitTotal;
            this.itemOrder = this.formInitData.itemOrder;
          }
          this.industry = this.formInitData.industry;
          this.tenderMode = this.formInitData.tenderMode;
          this.industryChangeFn("init");
          // this.industryInitFn();
          this.formData = JSON.parse(JSON.stringify(this.formInitData));
          // 人工见证事项-编辑时-显示的是多选下拉菜单-禁止修改
          this.formData.statusArr = [this.formData.status];
          this.statusArrOld = this.formData.statusArr;
          console.log(" this.formData", this.formData);
          // 默认-系统
          // TODO 816
          if (this.formData.valueCode === "YES") {
            // this.scenesOptions = this.taskObj.witnessScene.filter((item) => !item.children);
            this.scenesOptions = this.taskObj.witnessScene.filter((item) => item.value === "EXISTING");
          } else {
            this.scenesOptions = this.taskObj.witnessScene;
          }
          if (this.scenesOptions.length === 1) {
            this.formData.scenes = [this.scenesOptions[0].value];
          }
          // if (this.type === "add") {
          this.taskObj.witnessScene.forEach((item) => {
            item.children &&
              item.children.forEach((itemB) => {
                const value = Array.isArray(this.formData.scenes) ? this.formData.scenes[0] : this.formData.scenes;
                if (itemB.value === value) {
                  this.formData.scenes = [item.value, itemB.value];
                  // this.formData.statusArr = [this.formData.status];
                }
              });
          });
          // }
          setTimeout(() => {
            this.$refs.formDataAdd && this.$refs.formDataAdd.clearValidate(); // 清空
          }, 50);
          // this.$refs.formDataAdd && this.$refs.formDataAdd.resetFields(); // 清空/编辑时会报错
        }
      }
    },
    destroyed() {
      this.$refs.formDataAdd && this.$refs.formDataAdd.clearValidate(); // 清空
    },
    beforeDestroy() {
      this.$refs.formDataAdd && this.$refs.formDataAdd.clearValidate(); // 清空
    },
    methods: {
      shixiangDataChange(e) {
        console.log("e", e);
        this.shixiangDataChildrenZC = [];
        this.shixiangDataChildrenYC = [];
        const arr = [];
        const arrs = [];
        this.shixiangData.map((titem) => {
          if (e === titem.itemCode) {
            console.log("titem.itemCode", titem);
            titem.children.forEach((itemB) => {
              if (itemB.itemStatus === "NORMAL_TYPE") {
                arr.push({
                  isSystem: itemB.isSystem,
                  itemStatus: itemB.itemStatus,
                  defaultItem: itemB.defaultItem,
                  sceneRecord: itemB.itemName,
                  itemCode: itemB.itemCode,
                  itemConfigId: itemB.itemConfigId
                });
                // this.shixiangDataChildrenZC.push(itemB);
              } else {
                arrs.push({
                  isSystem: itemB.isSystem,
                  itemStatus: itemB.itemStatus,
                  defaultItem: itemB.defaultItem,
                  sceneRecord: itemB.itemName,
                  itemCode: itemB.itemCode,
                  itemConfigId: itemB.itemConfigId
                });
                // this.shixiangDataChildrenYC.push(itemB);
              }
              // this.formData = {
              //   valueCode: titem.isSystem,
              //   jianzheng: titem.itemCode,
              //   domains: arr,
              //   domainss: arrs
              // };
            });
            const domainsDefault = arr.filter((item) => item.defaultItem === "DEFAULT");
            const domainssDefault = arrs.filter((item) => item.defaultItem === "DEFAULT");
            if (domainsDefault.length < 1) {
              arr[0].defaultItem = "DEFAULT";
            }
            if (domainssDefault.length < 1) {
              arrs[0].defaultItem = "DEFAULT";
            }
            this.formData.valueCode = titem.isSystem;
            this.formData.jianzheng = titem.itemCode;
            this.formData.domains = arr;
            this.formData.domainss = arrs;
          }
        });
        // this.tableTaskList.forEach((i) => {
        //   this.shixiangData.forEach((j) => {
        //     if (i.itemName == j.itemName) {
        //       j.disabled = true;
        //     }
        //   });
        // });
      },
      changeCodDomainZC() {
        this.formData.domains.map((ditem) => {
          this.shixiangDataChildrenZC.map((titem) => {
            if (ditem.itemCode === titem.itemCode) {
              titem.disabled = true;
            }
          });
        });
      },
      changeCodDomainYC() {
        this.formData.domainss.map((ditem) => {
          this.shixiangDataChildrenYC.map((titem) => {
            if (ditem.itemCode === titem.itemCode) {
              titem.disabled = true;
            }
          });
        });
      },
      removeDomains(item) {
        console.log("item1111", item);
        if (item.isSystem === "YES") {
          this.$message({
            type: "warning",
            message: "系统数据不可删除！",
            single: true
          });
        } else {
          const index = this.formData.domainss.indexOf(item);
          // if (this.xugai === "edit") {
          //   // if (item.isSystem === "NO" || !item.sceneRecord) {
          //   if (index !== -1) {
          //     this.formData.domainss.splice(index, 1);
          //   }
          //   if (item.itemConfigId) {
          //     this.deleteIds.push(item.itemConfigId);
          //   }
          //   if (item.defaultItem === "DEFAULT") {
          //     this.formData.domainss[0].defaultItem = "DEFAULT";
          //   }
          //   // } else if (index !== -1) {
          //   //   this.formData.domainss.splice(index, 1);
          //   // }
          // } else {
          if (index !== -1) {
            this.formData.domainss.splice(index, 1);
          }
          if (item.itemConfigId) {
            this.deleteIds.push(item.itemConfigId);
          }
          if (item.defaultItem === "DEFAULT") {
            this.formData.domainss[0].defaultItem = "DEFAULT";
          }
          // }
          if (this.formData.valueCode === "YES") {
            this.shixiangDataChildrenYC.map((titem) => {
              if (item.itemCode === titem.itemCode) {
                titem.disabled = false;
              }
            });
          } else {
            this.shixiangDataChildrenYC.map((titem) => {
              if (item.itemCode === titem.itemCode) {
                titem.disabled = false;
              }
            });
          }
        }
      },
      addDomains() {
        if (this.xugai === "edit") {
          if (this.formData.valueCode === "YES") {
            this.formData.domainss.push({
              itemConfigId: "",
              sceneRecord: "",
              defaultItem: "NON_DEFAULT",
              itemStatus: "EXCEPTION_TYPE"
            });
          } else {
            this.formData.domainss.push({
              itemConfigId: "",
              itemCode: "",
              sceneRecord: "",
              defaultItem: "NON_DEFAULT",
              itemStatus: "EXCEPTION_TYPE"
            });
          }
        } else {
          this.formData.domainss.push({
            itemCode: "",
            sceneRecord: "",
            defaultItem: "NON_DEFAULT",
            itemStatus: "EXCEPTION_TYPE"
          });
        }
      },
      removeDomain(item) {
        console.log(item);
        const index = this.formData.domains.indexOf(item);
        if (item.isSystem === "YES") {
          this.$message({
            type: "warning",
            message: "系统数据不可删除",
            single: true
          });
          return;
        }
        // if (this.xugai === "edit") {
        //   if (item.isSystem === "NO" || item.sceneRecord === "") {
        //     if (index !== -1) {
        //       this.formData.domains.splice(index, 1);
        //     }
        //     if (item.itemConfigId) {
        //       this.deleteIds.push(item.itemConfigId);
        //     }
        //     if (item.defaultItem === "DEFAULT") {
        //       this.formData.domains[0].defaultItem = "DEFAULT";
        //     }
        //   } else if (index !== -1) {
        //     this.formData.domains.splice(index, 1);
        //   }
        // } else {
        if (index !== -1) {
          this.formData.domains.splice(index, 1);
        }
        if (item.defaultItem === "DEFAULT") {
          this.formData.domains[0].defaultItem = "DEFAULT";
        }
        if (item.itemConfigId) {
          this.deleteIds.push(item.itemConfigId);
        }
        // }
        if (this.formData.valueCode === "YES") {
          this.shixiangDataChildrenZC.map((titem) => {
            if (item.itemCode === titem.itemCode) {
              titem.disabled = false;
            }
          });
        } else {
          this.shixiangDataChildrenZC.map((titem) => {
            if (item.itemCode === titem.itemCode) {
              titem.disabled = false;
            }
          });
        }
      },
      addDomain() {
        if (this.xugai === "edit") {
          if (this.formData.valueCode === "YES") {
            this.formData.domains.push({
              itemConfigId: "",
              sceneRecord: "",
              defaultItem: "NON_DEFAULT",
              itemStatus: "NORMAL_TYPE"
            });
          } else {
            this.formData.domains.push({
              itemCode: "",
              itemConfigId: "",
              sceneRecord: "",
              defaultItem: "NON_DEFAULT",
              itemStatus: "NORMAL_TYPE"
            });
          }
        } else {
          this.formData.domains.push({
            itemCode: "",
            sceneRecord: "",
            defaultItem: "NON_DEFAULT",
            itemStatus: "NORMAL_TYPE"
          });
        }
      },
      ridioChange(e) {
        this.formData.domains.forEach((i, index) => {
          if (e === index) {
            i.defaultItem = "DEFAULT";
          } else {
            i.defaultItem = "NON_DEFAULT";
          }
        });
      },
      ridioChanges(e) {
        this.formData.domainss.forEach((i, index) => {
          if (e === index) {
            i.defaultItem = "DEFAULT";
          } else {
            i.defaultItem = "NON_DEFAULT";
          }
        });
      },
      // 行业
      industryInitFn() {
        const arr = this.taskObj.industryTypeAndIndustry.find((item) => item.value === this.industry);
        console.log("arr", arr);
        // statusOptions
        this.liveStatusArr = arr.children;
        console.log("this.liveStatusArr", this.liveStatusArr);
        const tenderModeFlag = this.liveStatusArr.some((item) => item.value === this.tenderMode);
        if (!tenderModeFlag) {
          this.tenderMode = this.liveStatusArr[0].value || "";
        }
        // 见证环节
        const currModeObj = this.liveStatusArr.find((item) => item.value === this.tenderMode);
        console.log("currModeObj", currModeObj);
        // this.statusOptions = currModeObj.children;
        const linkArr = [];
        console.log("this.statusOptions", this.statusOptions);
        console.log("this.taskObj.taskWitnessLink", this.taskObj.taskWitnessLink);
        this.taskObj.taskWitnessLink.forEach((itemA) => {
          const curr = currModeObj.children.find((itemB) => itemB.abridge === itemA.value);
          if (curr) {
            linkArr.push(curr);
          }
        });
        console.log("linkArr", linkArr);
        this.statusOptions = linkArr;
        // console.log("this.statusOptions", this.statusOptions);
        if (!this.statusOptions.some((item) => item.abridge === this.formData.status)) {
          this.formData.status = this.statusOptions[0].abridge || "";
        }
        this.formData.statusArr = [this.formData.status];
        this.formDataInitFn();
      },
      // 行业
      async industryChangeFn(val) {
        console.log("val", val);
        await this.industryInitFn();
        // industryTypeAndTenderMode
        // const arr = this.taskObj.industryTypeAndIndustry.find((item) => item.value === this.industry);
        // this.liveStatusArr = arr.children;
        const flag = this.liveStatusArr.some((item) => item.value === this.tenderMode);
        if (!flag) {
          this.tenderMode = "";
        } else {
          // 见证事项
          this.getShixiangDataFn(val);
        }
      },
      // 交易方式
      tenderModeFn(val) {
        console.log("val", val);
        const currModeObj = this.liveStatusArr.find((item) => item.value === this.tenderMode);
        console.log("currModeObj", currModeObj);
        // this.statusOptions = currModeObj.children;
        const linkArr = [];
        console.log("this.statusOptions", this.statusOptions);
        console.log("this.taskObj.taskWitnessLink", this.taskObj.taskWitnessLink);
        this.taskObj.taskWitnessLink.forEach((itemA) => {
          const curr = currModeObj.children.find((itemB) => itemB.abridge === itemA.value);
          if (curr) {
            linkArr.push(curr);
          }
        });
        console.log("linkArr", linkArr);
        this.statusOptions = linkArr;
        // console.log("this.statusOptions", this.statusOptions);
        if (!this.statusOptions.some((item) => item.abridge === this.formData.status)) {
          this.formData.status = this.statusOptions[0].abridge || "";
        }
        // 多选，切交易方式
        // if (!this.statusOptions.some((item) => item.abridge === this.formData.status)) {
        this.formData.statusArr = [this.formData.status];
        // }
        // 见证事项
        this.getShixiangDataFn();
        this.formDataInitFn();
      },
      // 见证场景
      scenesChangeFn(val) {
        console.log("val", val);
        console.log("this.formData", this.formData);
        // 见证事项
        // this.getShixiangDataFn();
        // this.formDataInitFn();
        // // 'STOP/RECOVER'
        // if (val[0] === "EXISTING") {
        //   if (this.formData.statusArr.length) {
        //     [this.formData.status] = this.formData.statusArr;
        //   } else {
        //     this.formData.status = this.statusOptions[0].value;
        //   }
        //   this.formData.statusArr = [this.formData.status];
        //   this.statusChangeFn(this.formData.status);
        // } else if (this.formData.statusArr.length === 1) {
        //   [this.formData.status] = this.formData.statusArr;
        //   this.statusChangeFn(this.formData.status);
        //   // } else {
        //   // this.formData.statusArr = [this.formData.status];
        // }
        // this.formData.status = this.statusOptions.some();
      },
      // 见证环节
      statusArrBlurFn(val) {
        console.log("val", val);
        if (val === false) {
          this.getShixiangDataFn();
        }
      },
      statusArrChangeFn(val, e) {
        console.log("val", val);
        console.log("e", e);
        // console.log("witnessLink", this.witnessLink);
        // // this.rightsForm.witnessLink;
        // TODO 根据下拉菜单排序 ==============================这里需要改
        const linkArr = [];
        this.taskObj.taskWitnessLink.forEach((item) => {
          if (val.some((itemB) => itemB === item.value)) {
            linkArr.push(item.value);
          }
        });
        // console.log("linkArr", linkArr);
        // this.rightsForm.witnessLink = linkArr;
        this.formData.statusArr = linkArr;
        if (val.length > 0) {
          this.formData.status = linkArr[0];
          // this.statusChangeFn(val[0]);
          // if (!this.getShixiangFlag) {
          //   this.getShixiangFlag = setTimeout(async () => {
          //     this.getShixiangFlag = null;
          // await this.getShixiangDataFn();
          // }, 500);
          // }
          // this.formDataInitFn();
        } else {
          this.formData.statusArr = this.statusArrOld;
        }
        // 这个给见证环节选择加个限制，交互能简单些，见证环节是必输的，那就最少要选一个，不能全不选
        this.statusArrOld = this.formData.statusArr;
      },
      // 见证环节
      statusChangeFn(val) {
        console.log("val", val);
        this.formData.statusArr = [val];
        // 见证事项
        this.getShixiangDataFn();
        this.formDataInitFn();
        this.formData.status = val;
      },
      async getShixiangDataFn(val) {
        console.log("val", this.formData.status);
        // 这里不合理，阻止了行业、交易方式切换
        // if (this.formData.status === this.linkValOld) {
        //   return;
        // }
        // this.linkValOld = this.formData.status;
        this.formDataLoading = true;
        const obj = {
          industry: this.industry,
          tenderMode: this.tenderMode,
          status: this.formData.status,
          init: val
        };
        console.log("obj", obj);
        // 见证事项
        await this.$emit("getShixiangDataFn", obj);
      },
      // cancelFn() {
      //   this.visible = false;
      // },
      cancelFn() {
        this.closeFn();
      },
      closeFn() {
        // this.$refs.formDataAdd.resetFields(); // 清空
        this.$emit("close");
      },
      itemOrderChangeFn(val) {
        console.log("val", val);
      },
      radioBox(e) {
        // <el-radio label="YES">系统预置事项</el-radio>
        // <el-radio label="NO">自定义事项</el-radio>
        if (e === "YES") {
          // this.scenesOptions = this.taskObj.witnessScene.filter((item) => !item.children);
          this.scenesOptions = this.taskObj.witnessScene.filter((item) => item.value === "EXISTING");
        } else {
          this.scenesOptions = JSON.parse(JSON.stringify(this.taskObj.witnessScene));
          // if (!this.scenesOptions.some((item) => item.label === "人工见证事项")) {
          //   this.scenesOptions.push({ label: "人工见证事项", value: "PEOPLE" });
          // }
        }
        // formData.scenes
        this.shixiangDataChildrenYC.map((titem) => {
          titem.disabled = false;
        });
        this.shixiangDataChildrenZC.map((titem) => {
          titem.disabled = false;
        });
        //   status: this.formInitData.status,
        //   statusArr: [this.formInitData.status],
        // this.$set(this.formData, "status", this.formInitData.status);
        // this.$set(this.formData, "statusArr", [this.formInitData.status]);
        this.formDataInitFn();
        // this.$refs.formDataAdd && this.$refs.formDataAdd.clearValidate(); // 清空
        // this.$refs.formDataAdd && this.$refs.formDataAdd.resetFields(); // 清空
        setTimeout(() => {
          if (
            this.scenesOptions.length === 1 ||
            !this.scenesOptions.some((item) => item.value === this.formData.scenes)
          ) {
            this.formData.scenes = [this.scenesOptions[0].value];
            // this.$set(this.formData, "statusArr", [this.formInitData.status]);
            // this.formData.statusArr = [this.statusOptions[0].abridge];
            // this.formData.status = this.statusOptions[0].abridge;
            // } else {
            //   if () {
            //     this.$set(this.formData, "scenes", [this.scenesOptions[0].value]);
            //   }
            // this.formData.scenes = [this.scenesOptions[0].value];
          }
          //   v-model="formData.statusArr"
          //   style="width: 290px"
          //   placeholder="请选择"
          // >
          //   <el-option v-for="item in statusOptions"
        }, 50);
      },
      // 初始化组件
      pageInitFn() {
        this.formDataInitFn();
        // this.linkValOld = null;
        this.linkValOld = null;
        this.statusArrOld = null;
        this.liveStatusArr = [];
        this.statusOptions = [];
        this.scenesOptions = [];
        this.shixiangData = [];
        this.shixiangDataChildrenYC = [];
        this.shixiangDataChildrenZC = [];
        this.industry = "";
        this.tenderMode = "";
        this.itemOrder = ""; // 排序
        this.orderTotal = 0; // 排序下拉
      },
      // 初始化表单
      formDataInitFn() {
        this.$refs.formDataAdd && this.$refs.formDataAdd.clearValidate(); // 清空
        this.shixiangDataChildrenYC = [];
        this.shixiangDataChildrenZC = [];
        console.log("this.formInitData", this.formInitData);
        // 赋值影响见证环节
        // this.formData = {
        //   // scenes:,
        //   valueCode: this.formData.valueCode,
        //   scenes: this.formData.scenes,
        //   status: this.formInitData.status,
        //   statusArr: [this.formInitData.status],
        //   jianzheng: ""
        //   // domains: [
        //   //   {
        //   //     itemCode: "",
        //   //     sceneRecord: "",
        //   //     defaultItem: "DEFAULT",
        //   //     itemStatus: "NORMAL_TYPE"
        //   //   }
        //   // ],
        //   // domainss: [
        //   //   {
        //   //     itemCode: "",
        //   //     sceneRecord: "",
        //   //     defaultItem: "DEFAULT",
        //   //     itemStatus: "EXCEPTION_TYPE"
        //   //   }
        //   // ]
        // };
        this.$set(this.formData, "domains", [
          {
            itemCode: "",
            sceneRecord: "",
            defaultItem: "DEFAULT",
            itemStatus: "NORMAL_TYPE"
          }
        ]);
        this.$set(this.formData, "domainss", [
          {
            itemCode: "",
            sceneRecord: "",
            defaultItem: "DEFAULT",
            itemStatus: "EXCEPTION_TYPE"
          }
        ]);
        this.$set(this.formData, "jianzheng", "");
      },
      submitFn() {
        console.log("=======");
        this.$refs["formDataAdd"].validate((valid) => {
          if (valid) {
            console.log("valid", valid);
            console.log("this.formData", this.formData);
            console.log("this.formData.statusArr", this.formData.statusArr);
            console.log("this.statusOptions", this.statusOptions);
            const domainsDefault = this.formData.domains.filter((item) => item.defaultItem === "DEFAULT");
            const domainssDefault = this.formData.domainss.filter((item) => item.defaultItem === "DEFAULT");
            if (domainsDefault.length !== 1 || domainssDefault.length !== 1) {
              this.$message({
                type: "error",
                message: "请选择见证事项的默认选项",
                single: true
              });
              return;
            }
            // 场景为 暂停/恢复、人工
            if (Array.isArray(this.formData.scenes) && this.formData.scenes[0] !== "EXISTING") {
              // 见证环节
              if (this.formData.statusArr.length > 1) {
                const arr = [];
                this.formData.statusArr.forEach((itemA) => {
                  const obj = this.statusOptions.find((itemB) => itemB.abridge === itemA);
                  console.log("obj", obj);
                  arr.push(obj.label);
                });
                console.log("arr", arr);
                this.$confirm(`您确认将新增的见证事项同步设置到这些见证环节么（${arr.join(", ")}）？`, "提示", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning"
                })
                  .then(() => {
                    this.conFn();
                  })
                  .catch(() => {});
              } else {
                this.conFn();
              }
            } else {
              // 既定
              this.formData.statusArr = null;
              this.conFn();
            }
          }
        });
        // this.$emit("submitFn", {});
        // this.$nextTick(() => {
        //   if (this.type === "random") {
        //     this.subtaskAllocateUserRandomFn();
        //   } else {
        //     this.subtaskAllocateUserFn();
        //   }
        // });
      },
      conFn() {
        this.loadingBtn = true;
        let arr = [];
        console.log("this.formData.domains", this.formData.domains);
        let str = "shouDong";
        if (this.formData.valueCode === "NO") {
          // this.shouDong();
        } else {
          str = "xiTongAdd";
        }
        if (this.type === "edit") {
          str = "itemDictUpdateFn";
        }
        arr = arr.concat(this.formData.domains, this.formData.domainss);
        arr.forEach((item) => {
          // console.log("itemaaa.itemCode", item.itemCode);
          item.itemCode = item.itemCode || "";
        });
        // console.log("system", arr);
        // console.log(" this.formData.scenes", this.formData.scenes);
        console.log("deleteIds");
        const { deleteIds } = this;
        const witnessScene = Array.isArray(this.formData.scenes)
          ? this.formData.scenes[this.formData.scenes.length - 1]
          : this.formData.scenes;
        // 编辑和添加数据格式不一样 statusArr，编辑接受字符串
        // const itemOrder = this.formData.statusArr === null ? this.itemOrder : null;
        this.$emit("submitFn", str, {
          industry: this.industry,
          tenderMode: this.tenderMode,
          status: this.formData.status,
          statusArr: this.formData.statusArr,
          jianzheng: this.formData.jianzheng,
          itemOrder: this.itemOrder,
          deleteIds,
          witnessScene,
          arr
        });
        // this.formData
      }
    }
  };
</script>
<style lang="scss" scoped>
  .hide-form-label-sign {
    ::v-deep .el-form-item__label:after {
      display: none;
    }
  }
  // .witness-matters-dialog {
  //   ::v-deep .el-dialog__body {
  //     overflow-x: hidden;
  //     max-height: 456px;
  //   }
  // }
</style>
